package com.loongtech.bi.manager.realTime;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.loongtech.bi.entity.realTime.EntityRealTimePcu;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;

/**
 * 
 * @author marin
 * @date 2015-09-15
 */
@Service
public class RealTimePcuManager extends ManagerQueryCacheBase<EntityRealTimePcu> {
	private static final long serialVersionUID = 1L;
	
	public List<EntityRealTimePcu> getPcuRealTimeDatas(Date lookDate, List<String> serverids) {
		if (serverids == null || serverids.size() <= 0) {
			return null;
		}
		
		return findByQuery("from EntityRealTimePcu where day<=:dayStart and day>=:dayEnd and platformid=:platformid and channelid=:channelid and serverid in (:serverid)", "dayStart", new Date(Time.getBeginningOfDay(lookDate.getTime())), "dayEnd", new Date(Time.getBeginningOfDay(lookDate.getTime() - Time.DAY * 15)), "platformid", "0", "channelid", "0", "serverid", serverids);
	}
	
	public List<Object[]> getAllPcuRealTimeDatas(Date lookDate) { 
		return findByQuery("select a.serverid,a.pcu from EntityRealTimePcu as a where a.day=:dayStart and a.platformid=:platformid and a.channelid=:channelid and a.serverid != :serverid", "dayStart", new Date(Time.getBeginningOfDay(lookDate.getTime())), "platformid", "0", "channelid", "0", "serverid", "0");
	}
}